package homework.day02;

import javax.swing.*;
import java.awt.*;

public class twoJpanel extends JPanel implements Runnable{
    int x=810;//黑色月亮
    int y=170;

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        this.setBackground(Color.BLACK);
        g.setColor(Color.WHITE);
        //画月亮
        g.fillOval(860,120,60,60);

        //会动的黑色的圆
        g.setColor(Color.BLACK);
        g.fillOval(x,y,60,60);
    }

    @Override
    public void run() {
        while(true){
            x++;
            y--;
            if(x>1024&&y<0){
                x=810;
                y=170;
            }
            try{
                Thread.sleep(100);
            }catch(InterruptedException e) {
                e.printStackTrace();
            }
            repaint();
        }

    }
}
